// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import VueRouter from "vue-router";
import env from '@/assets/js/baseJS/env.js'
import { Tabbar, TabbarItem } from 'vant';

import './assets/icon/iconfont/iconfont.css'
import './assets/css/common.css'
import webSocket from './assets/js/socket/webSocket.js'
import { Icon } from 'vant';
import { Toast } from 'vant';

Vue.use(Icon);
Vue.use(Toast);
Vue.use(Tabbar).use(TabbarItem);
Vue.config.productionTip = false
Vue.use(VueRouter);
//在登陆成功后 连接websocket
Vue.prototype.$websocket = webSocket
Vue.prototype.$webUrl = env.WebSocket.wsUrl



//err异常处理
// Vue.config.errorHandler = function(err, vm, info) {
//   console.log(`Error: ${err.toString()}\nInfo: ${info}`);
// };


router.beforeEach((to,form,next)=>{
  //排除登录页面
  if (window.localStorage.getItem('user') && to.path!= '/login') {
    if(webSocket.state.websock==null){
      console.log("已登录,重连...");
      let data={
        url:env.WebSocket.wsUrl,
        id:JSON.parse(window.localStorage.getItem('user')).id
      }
      webSocket.dispatch('WEBSOCKET_INIT',data);
    }
    next()
  } else {
    if(to.path=== '/login'){
      next()
    }else{
      next('/login')
    }

  }
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
